<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加减计数器</title>
    <style>
        .counter {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 50px;
        }
        .counter button {
            padding: 10px 20px;
            font-size: 18px;
            cursor: pointer;
        }
        .counter span {
            margin: 0 10px;
            font-size: 20px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="counter">
        <button id="decrement">-</button>
        <span id="count">1</span>
        <button id="increment">+</button>
    </div>

    <script>
        // 获取元素
        const decrementButton = document.getElementById('decrement');
        const incrementButton = document.getElementById('increment');
        const countDisplay = document.getElementById('count');

        // 初始化计数器
        let count = 1;

        // 增加按钮点击事件
        incrementButton.addEventListener('click', () => {
            count++;
            countDisplay.textContent = count;
        });

        // 减少按钮点击事件
        decrementButton.addEventListener('click', () => {
            count--;
            countDisplay.textContent = count;
        });
    </script>
</body>
</html>